package service;

import java.util.List;

import beans.CarBean;
import db.CarDAO;

public class CarService {
	public List<CarBean> browse() {
		CarDAO dao = new CarDAO();
		return dao.getAllRecords();
	}

	public List<CarBean> browse(String asset_number, String usage_status, String car_name, String license_plate) {
		CarDAO dao = new CarDAO();
		dao.setAsset_number(asset_number);
		dao.setCar_name(car_name);
		dao.setLicense_plate(license_plate);
		dao.setUsage_status(usage_status);
		return dao.getAllRecords();
	}

	public CarBean getRecord(int carId) {
		CarDAO carDao = new CarDAO();
		return carDao.getRecord(carId);
	}

	public boolean addCar(CarBean car) {
		CarDAO carDao = new CarDAO();
		return carDao.insertRecord(car);
	}

	public boolean editCar(CarBean beforeRecord, CarBean afterRecord) {
		CarDAO carDao = new CarDAO();
		return carDao.updateRecord(beforeRecord, afterRecord);
	}

	public int delCar(CarBean car) {
		CarDAO carDao = new CarDAO();
		if (carDao.deleteRecord(car))
			return 1;
		else
			return 2;
	}
}
